home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Plotting / aa_Intel_Only / Gnuplot / GnuplotSource / PopUpScrollView.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  2.7 KB  |  153 lines

  1. /*
  2.  *  Copyright (C) 1993  Robert Davis
  3.  *
  4.  *  This program is free software; you can redistribute it and/or
  5.  *  modify it under the terms of Version 2, or any later version, of 
  6.  *  the GNU General Public License as published by the Free Software 
  7.  *  Foundation.
  8.  */
  9.  
  10. static char RCSId[]="$Id: PopUpScrollView.m,v 1.3 1993/05/04 16:22:36 davis Exp $";
  11.  
  12.  
  13. #import <appkit/Matrix.h>
  14. #import <appkit/PopUpList.h>
  15.  
  16. #import <objc/List.h>
  17.  
  18. #import "PopUpScrollView.h"
  19. #import "PlotView.h"
  20.  
  21. #define UNDEFINED    -1.0    /* See [Control selectedTag]    */
  22. #define DEFAULTTAG    100    /* Default tag upon init is 100    */
  23.  
  24.  
  25. @implementation PopUpScrollView
  26.  
  27.  
  28. - initFrame:(const NXRect *)frameRect
  29. {
  30.     [super initFrame:frameRect];
  31.     oldTag = UNDEFINED;
  32.     return self;
  33. }
  34.  
  35.  
  36. - free
  37. {
  38.     /*  
  39.      *  A pop-up button's target is a PopUpList that won't be freed 
  40.      *  when the popUpButton is freed.  So we must free it here.
  41.      */
  42.     [[popUpButton target] free];
  43.     return [super free];
  44. }
  45.  
  46.  
  47. - changeScale:sender
  48. {
  49.     int theTag = [sender selectedTag];
  50.  
  51.     if (theTag != oldTag)  {
  52.     oldTag = theTag;
  53.     return [self setCurrentTag: theTag];
  54.     } else
  55.     return nil;
  56. }
  57.  
  58.  
  59. /* 1.00 scaleFactor == 100% */
  60.  
  61. - changeScaleTo:(float)scaleFactor
  62. {
  63.     [[self docView] scale:scaleFactor];
  64.     return self;
  65. }
  66.  
  67.  
  68.  
  69. - tile
  70. {
  71.     NXRect scrollerRect, buttonRect;
  72.  
  73.     [super tile];
  74.  
  75.     if ([popUpButton superview] != self) {
  76.     [self addSubview:popUpButton];
  77.     }
  78.  
  79.     /*
  80.      *  Now make the hScroller smaller and stick the popUpButton next 
  81.      *  to it.
  82.      */
  83.     [hScroller getFrame:&scrollerRect];
  84.     NXDivideRect(&scrollerRect, &buttonRect, 90.0, 2);
  85.     [hScroller setFrame:&scrollerRect];
  86.     [popUpButton setFrame:&buttonRect];
  87.     
  88.     return self;
  89. }
  90.  
  91.  
  92.  
  93. - update
  94. {
  95.     [self setCurrentTag:[self currentTag]];
  96.     return self;
  97. }
  98.  
  99.  
  100.  
  101. - setCurrentTag:(int)aTag
  102. {
  103.     int    i, count;
  104.     id    cell, cells;
  105.     id value = nil;
  106.  
  107.     cell = [[popUpButton target] findCellWithTag:aTag];
  108.  
  109.     /* 
  110.      *  Check to make sure the tag is a valid selection (i.e. that it 
  111.      *  is in the PopUpList.  If not, we don't do anything.  (Note 
  112.      *  that we do not add aTag to the list.)
  113.      */
  114.     
  115.     cells = [[[popUpButton target] itemList] cellList];
  116.     count = [cells count];
  117.  
  118.     for(i = 0; i < count; i++)  {
  119.     if ([cells objectAt:i] == cell)  {
  120.         [popUpButton setTitle: [cell title]];
  121.         value = self;
  122.         [self changeScaleTo: [cell tag] / 100.0];
  123.         oldTag = aTag;
  124.         break;
  125.     }
  126.     }
  127.  
  128.     return value;
  129. }
  130.  
  131.  
  132. - (int)currentTag
  133. {
  134.     int aTag;
  135.  
  136.     aTag = [[[popUpButton target] itemList] selectedTag];
  137.  
  138.     if (aTag != UNDEFINED)
  139.     return aTag;
  140.     else
  141.     return DEFAULTTAG;
  142. }
  143.  
  144.  
  145. // Shuts up the compiler about unused RCSId
  146. - (const char *) rcsid
  147. {
  148.     return RCSId;
  149. }
  150.  
  151.  
  152. @end
  153.